<html>

<body>
<h1>Calculator</h1>

<form method="get" ACTION = "http://192.168.56.20/~cs143/calculator.php">
<input type ="text" name="expr"> <input type="submit" value="Calculate"> 
</form>

<?php
if($_GET["expr"]){
	$expr = $_GET["expr"];
$expr = str_replace(" ","",$expr);
$newexpr = preg_replace("[--]","+",$expr); 
if(preg_match("#^([-]?([0-9]*?.)?[0-9]+)([-+/*][-]?([0-9]*?.)?[0-9]+)*$#" , $newexpr))
{
	@eval("\$ans=$newexpr;");
	echo $expr ." = ". $ans;
}
else
{
	echo "Invalid input expression " . $expr;
}
}

?>

</body>
</html>
